import java.util.concurrent.Semaphore;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Jiang Jinxi
 * Date: 2024-09-03
 * Time: 17:13
 */
public class Demo35 {
    static Semaphore semaphore = new Semaphore(4);//设置初识资源数, 相当于计数器初始值

    public static void main(String[] args) throws InterruptedException {
        semaphore.acquire();
        System.out.println("P操作");
        semaphore.acquire();
        System.out.println("P操作");
        semaphore.acquire();
        System.out.println("P操作");
        semaphore.acquire();
        System.out.println("P操作");
        semaphore.acquire();
        System.out.println("P操作");
        semaphore.release();
        System.out.println("V操作");


    }
}
